package top.infopub.mgr.bpast.service.impl;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.bpast.dao.DynamicNormDao;
import top.infopub.mgr.bpast.service.DynamicNormService;
import top.infopub.mgr.util.DateUtils;
import top.infopub.model.bpast.DynamicNorm;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;

@Service
public class DynamicNormServiceImpl extends GenericServiceImpl<DynamicNorm, String> implements
		DynamicNormService {

	@Autowired
	private DynamicNormDao dynamicNormDao;
	
	@Override
	public GenericDao<DynamicNorm, String> getDao() {
		return dynamicNormDao;
	}

    @Override
    public Page<DynamicNorm> selectDataByWhere(Date monthStart, Date monthEnd, String type,
                                                   String orgId, String orgProName, Page<DynamicNorm> page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        Map<String, Object> where = Maps.newHashMap();
        where.put("stsMonthStart", monthStart);
        Date stsMonthEnd = DateUtils.getMonthEnd(monthEnd);
        where.put("stsMonthEnd", stsMonthEnd);
        if(type.equals("2")){//区域公司
            where.put("hrOrgAreaId", orgId);
        }else if(type.equals("3")){//项目公司
            where.put("hrOrgProId", orgId);
        }
        where.put("proName", orgProName);
        return (Page<DynamicNorm>)dynamicNormDao.selectDataByWhere(where);
    }

}